define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/shop/index' + location.search,
                    // add_url: 'shop/shop/add',
                    // edit_url: 'shop/shop/edit',
                    del_url: 'shop/shop/del',
                    multi_url: 'shop/shop/multi',
                    import_url: 'shop/shop/import',
                    table: 'shop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'shop_id',
                sortName: 'shop_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'shop_id', title: __('店铺id')},
                        {field: 'shopuser.nickname', title: __('申请人昵称')},
                        {field: 'shopuser.mobile', title: __('申请人手机号')},
                        // {field: 'category_id', title: __('Category_id')},
                        {field: 'shop_name', title: __('Shop_name'), operate: 'LIKE'},
                        {field: 'commission_rate', title: __('Commission_rate'), operate:'BETWEEN'},
                        {field: 'audit_status', title: __('状态'),searchList: {'-1': __('未提交'),0: __('认证中'),1: __('审核中'), 2: __('进件中'), 3: __('有效'), 4: __('驳回')},formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'channel_merchant_no', title: __('渠道商户号'), operate: 'LIKE'},
                        {field: 'channel_terminal_no', title: __('渠道终端号'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('详情'),
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'shop/shop/detail',
                                },
                                {
                                    name: 'bind',
                                    text: __('绑定商户'),
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'shop/shop/bind',
                                    visible:function(row){
                                        if(row.is_admin == 1&&row.merchant_status==3){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'unbind',
                                    text: __('解绑'),
                                    confirm:'确认解绑该商户吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'shop/shop/unbind',
                                    visible:function(row){
                                        if(row.is_admin == 1&&row.audit_status == 3){
                                            return true;
                                        }
                                    }
                                },
                               /* {
                                    name: 'audit',
                                    text: __('审核通过'),
                                    confirm:'确认审核通过该店铺吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'shop/shop/pass',
                                    visible:function(row){
                                        if(row.audit_status == 1){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'refuse',
                                    text: __('审核拒绝'),
                                    confirm:'确认审核拒绝该店铺吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-danger btn-xs btn-detail  btn-ajax',
                                    url: 'shop/shop/refuse',
                                    visible:function(row){
                                        if(row.audit_status == 1){
                                            return true;
                                        }
                                    }
                                },*/
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        bind: function () {
            Controller.api.bindevent();
        },
        unbind: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
